import matplotlib.pyplot as plt

# 定义一个函数来读取数据并返回x和y坐标列表
def read_bezier_data(filename):
    with open(filename, 'r') as file:
        x_coords = []
        y_coords = []
        for line in file:
            x, y = line.strip().split(',')
            x_coords.append(float(x))
            y_coords.append(float(y))
        return x_coords, y_coords

# 定义一个函数来绘制贝塞尔曲线
def plot_bezier_curve(filename, label):
    x_coords, y_coords = read_bezier_data(filename)
    plt.plot(x_coords, y_coords, label=label)

# 定义贝塞尔曲线数据文件的名称
m_values = [10,40,160]
for m in m_values:
        filename = f"./data/2F_{m}.txt"
        plot_bezier_curve(filename, f"m = {m}")

# 添加图例
plt.legend()

# 添加标题和轴标签
plt.title("Bezier Curve Approximation of a Heart Shape")
plt.xlabel("X")
plt.ylabel("Y")

# 显示网格
plt.grid(True)

# 保存图像
plt.savefig('./picture/2F.png', dpi=300, bbox_inches='tight')
